package com.by_man.presenter.module_health_management.health_advice;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;

import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.ImageRequest;
import com.android.volley.toolbox.Volley;
import com.by_man.presenter.R;
import com.by_man.presenter.SharedApplication;
import com.by_man.presenter.module_health_consultant.BitmapCache;
import com.by_man.repository.LocalDataManager;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import uk.co.senab.photoview.PhotoView;
import uk.co.senab.photoview.PhotoViewAttacher;

/**
 * 查看图片Activity
 * Created by man on 2017-02-21.
 */
public class PhotoViewActivity extends AppCompatActivity {
    private ImageLoader imageLoader;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_photo_view);
        //imageLoader = new ImageLoader(Volley.newRequestQueue(this),new BitmapCache());
        imageLoader = SharedApplication.getImageLoader(getApplication());
        initView();
    }

    private void initView() {
        final PhotoView photoView = (PhotoView) findViewById(R.id.photo_view);
        Intent intent = getIntent();
        final int position = intent.getIntExtra("position", 0);
        String pic_path = intent.getStringExtra("pic_path");
            // 加载图片
        ImageLoader.ImageListener listener = ImageLoader.getImageListener(photoView,
                R.drawable.no,R.drawable.no);
        imageLoader.get(pic_path,listener);
        photoView.setOnPhotoTapListener(new PhotoViewAttacher.OnPhotoTapListener() {
            @Override
            public void onPhotoTap(View view, float v, float v1) {
                Intent intent1 = new Intent(PhotoViewActivity.this, ChosedAdviceActivity.class);
                intent1.putExtra("position", position);
                intent1.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                PhotoViewActivity.this.startActivity(intent1);
                finish();
            }
        });
    }
}
